Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Website: Hero video optimization (subtitles, flickering) #944

Merged
merged 10 commits into from
Dec 3, 2024

Conversation

mdumond
Copy link
Contributor

@mdumond mdumond commented Nov 17, 2024

I replaced the call to an external file for the local translated versions. The files are correct in the html:

on live:
image

on the branch:
image

they don't appear yet though, but I also have trouble displaying the subtitles in the current main branch..

Also, the "label" argument is supposed to be the language name, I did not find in the code that we have a way to get that from the langcode, do we have something like that already?

Summary by CodeRabbit

  • New Features

    • Added support for video subtitles in multiple languages (German, English, French, Italian) to enhance accessibility.
    • Enhanced localization capabilities for the video component, allowing subtitles to adapt based on selected language and region.
  • Bug Fixes

    • Improved error handling for video loading issues, ensuring a smoother user experience.
  • Documentation

    • Updated component documentation to reflect new props and localization features.

Copy link

vercel bot commented Nov 17, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
public ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 3, 2024 8:40pm

Copy link

coderabbitai bot commented Nov 17, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

This pull request introduces a new key, "video-subtitle", to multiple JSON localization files, providing paths to subtitle files for video testimonials in German, English, French, and Italian. It also modifies the MuxVideoComponent and HeroVideo function to accept and utilize these subtitles dynamically based on language and region. The overall structure of the JSON files and existing functionalities of the components remain unchanged.

Changes

File Path Change Summary
shared/locales/de/website-home.json Added new key: "video-subtitle": "/assets/video/subtitle-video-testimonials.de_DE.vtt"
shared/locales/en/website-home.json Added new key: "video-subtitle": "/assets/video/subtitle-video-testimonials.en_US.vtt"
shared/locales/fr/website-home.json Added new key: "video-subtitle": "/assets/video/subtitle-video-testimonials.fr_FR.vtt"
shared/locales/it/website-home.json Added new key: "video-subtitle": "/assets/video/subtitle-video-testimonials.it_IT.vtt"
website/src/app/[lang]/[region]/(website)/(home)/(components)/mux-video.tsx Updated MuxVideoComponent to accept lang and translations props; added HeroVideoSubtitles type.
website/src/app/[lang]/[region]/(website)/(home)/(sections)/hero-video.tsx Updated HeroVideo to pass translations, lang, and region props to MuxVideoComponent.

Possibly related issues

Suggested reviewers

  • andrashee
  • socialincome-dev

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

github-actions bot commented Nov 17, 2024

Visit the preview URL for this PR (updated for commit bf69270):

https://si-admin-staging--pr944-934-video-subtitle-t-zrosyjgd.web.app

(expires Tue, 10 Dec 2024 18:58:54 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: b7b0969384059dce6ea8fad1ee1d1737e54e6676

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (7)
website/src/app/[lang]/[region]/(website)/(home)/(sections)/hero-video.tsx (2)

16-18: Add type safety for subtitle translations

Consider adding type definitions for the translations prop to ensure type safety and better IDE support.

+interface VideoTranslations {
+  subtitles: string;
+}

 <MuxVideoComponent
   translations={{
-    subtitles: translator.t<string>('video-subtitle'),
+    subtitles: translator.t<VideoTranslations>('video-subtitle').subtitles,
   }}

15-21: Regarding language name handling

In response to your question about language names: Instead of passing just the lang code, you might want to use the built-in Intl.DisplayNames API to get the language name. This would provide consistent language name formatting across browsers.

Example implementation:

const languageName = new Intl.DisplayNames([lang], { type: 'language' }).of(lang);

<MuxVideoComponent
  translations={{
    subtitles: translator.t<string>('video-subtitle'),
  }}
  lang={lang}
  region={region}
  languageLabel={languageName} // Add this prop to MuxVideoComponent
/>
website/src/app/[lang]/[region]/(website)/(home)/(components)/mux-video.tsx (1)

Line range hint 88-94: Consider improving subtitle styling maintainability.

The current subtitle styling could be enhanced for better maintainability and responsiveness:

Consider these improvements:

-       <style>{`
-        video::cue {
-          background-color: rgba(0, 0, 0, 0.8);
-          color: white;
-          font-family: Arial, sans-serif;
-          font-size: 24px;
-          opacity: ${showCaptions ? 1 : 0};
-      `}</style>
+       <style>{`
+        video::cue {
+          background-color: var(--subtitle-bg, rgba(0, 0, 0, 0.8));
+          color: var(--subtitle-color, white);
+          font-family: var(--subtitle-font, Arial, sans-serif);
+          font-size: clamp(16px, 2vw, 24px);
+          opacity: ${showCaptions ? 1 : 0};
+        }
+      `}</style>

This change:

  • Makes font size responsive using clamp
  • Uses CSS variables for easier theming
  • Improves maintainability by centralizing style values
shared/locales/en/website-home.json (1)

23-23: Consider restructuring subtitle configuration.

The subtitle path is currently at the root level of the JSON. Consider moving it under a dedicated "video" or "media" section for better organization and maintainability.

 {
+  "media": {
+    "video-subtitle": "/assets/video/subtitle-video-testimonials.en_US.vtt"
+  },
   "metadata": {
     ...
   },
-  "video-subtitle": "/assets/video/subtitle-video-testimonials.en_US.vtt",
   "section-1": {
     ...
   }
shared/locales/de/website-home.json (1)

23-23: Consider reorganizing the JSON structure

The video-subtitle key is placed between content sections. Consider moving it to a more logical location, such as under the metadata section or creating a dedicated media section for better organization and maintainability.

 {
 	"metadata": {
 		"title": "Social Income",
 		"description": "Change from human to human. From mobile to mobile.",
 		"og-image": "/assets/metadata/og/default.jpg",
-		"twitter-image": "/assets/metadata/twitter/default.jpg"
+		"twitter-image": "/assets/metadata/twitter/default.jpg",
+		"video-subtitle": "/assets/video/subtitle-video-testimonials.de_DE.vtt"
 	},
 	"section-1": {
shared/locales/it/website-home.json (1)

23-23: Consider adding a comment to document the subtitle path structure.

To maintain consistency across locales, consider adding a comment in the JSON file to document the expected format of the subtitle path:

+  // Format: /assets/video/subtitle-video-testimonials.[langcode]_[REGION].vtt
   "video-subtitle": "/assets/video/subtitle-video-testimonials.it_IT.vtt",
shared/locales/fr/website-home.json (1)

23-23: Consider adding language display names for accessibility.

Since the PR mentions uncertainty about retrieving language names from codes, consider adding a subtitle-language key to display user-friendly language names (e.g., "Français") in the video player's subtitle menu for better accessibility.

 {
+  "video-subtitle-language": "Français",
   "video-subtitle": "/assets/video/subtitle-video-testimonials.fr_FR.vtt",
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 64141ca and caccde3.

📒 Files selected for processing (6)
  • shared/locales/de/website-home.json (1 hunks)
  • shared/locales/en/website-home.json (1 hunks)
  • shared/locales/fr/website-home.json (1 hunks)
  • shared/locales/it/website-home.json (1 hunks)
  • website/src/app/[lang]/[region]/(website)/(home)/(components)/mux-video.tsx (3 hunks)
  • website/src/app/[lang]/[region]/(website)/(home)/(sections)/hero-video.tsx (1 hunks)
🔇 Additional comments (8)
website/src/app/[lang]/[region]/(website)/(home)/(sections)/hero-video.tsx (1)

15-21: Verify the translation key exists across all language files

The code retrieves subtitles using the 'video-subtitle' key. Let's ensure this key is properly defined in all language files.

✅ Verification successful

Translation key 'video-subtitle' is properly defined across all language files

The verification confirms that the 'video-subtitle' key exists in all language files (de, en, fr, it), ensuring proper internationalization support for the video subtitles.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if 'video-subtitle' key exists in all language files

# Find all website-home.json files and check for the key
fd --glob 'website-home.json' shared/locales | while read -r file; do
  echo "Checking $file..."
  jq 'has("video-subtitle")' "$file"
done

Length of output: 819

website/src/app/[lang]/[region]/(website)/(home)/(components)/mux-video.tsx (3)

13-17: LGTM! Well-structured type definition.

The HeroVideoSubtitles type is cleanly defined and properly extends DefaultParams using intersection types.


19-19: LGTM! Component signature properly updated.

The component signature has been correctly updated to accept language and translation props with proper typing.


87-87: ⚠️ Potential issue

Fix hardcoded language label in track element.

The label attribute is hardcoded as "English" while the srcLang is dynamic. This could be confusing for users when viewing subtitles in other languages.

Let's check if there's an existing language name utility in the codebase:

Consider updating the track element to use the correct language name:

- <track kind="captions" src={translations.subtitles} srcLang={lang} label="English" default />
+ <track kind="captions" src={translations.subtitles} srcLang={lang} label={getLanguageName(lang)} default />

If no existing utility is found, you might want to add one using the ISO 639-1 standard language codes. I can help implement this if needed.

✅ Verification successful

Let me search for language name translations in the locales directory:


Let me try searching for language translations in a different way:


Let me check the content of the common.json files to see the language translations:


Based on the findings, I can now generate the final response:

Use the existing i18n system for the track label

The codebase already has a translation system in place with language names. You can use the existing translator instance to get the language name:

- <track kind="captions" src={translations.subtitles} srcLang={lang} label="English" default />
+ <track kind="captions" src={translations.subtitles} srcLang={lang} label={translator.t(`languages.${lang}`)} default />
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for language name/code conversion utilities
rg -g '!*.test.*' -g '!*.spec.*' "langcode|language.*name|language.*code" -A 5

Length of output: 18888


Script:

#!/bin/bash
# Search for language translations in locales
fd "languages.json" --exec cat {} \;

Length of output: 39


Script:

#!/bin/bash
# Search for language translations in locales directory
rg -g '*.json' '"languages"' shared/locales

Length of output: 229


Script:

#!/bin/bash
# Check content of common.json files for language translations
fd "common.json" shared/locales --exec cat {} \; | grep -A 10 '"languages":'

Length of output: 760

shared/locales/en/website-home.json (1)

23-23: Verify subtitle file existence and structure.

The path references a VTT subtitle file. Let's ensure it exists and follows the same pattern across all locales.

✅ Verification successful

Subtitle files and naming patterns are consistent across locales

The verification shows:

  • All referenced VTT subtitle files exist in the correct location (website/public/assets/video/)
  • Consistent naming pattern subtitle-video-testimonials.[lang]_[REGION].vtt is followed across all locales
  • Each locale file correctly references its corresponding VTT file with matching language code
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify subtitle files existence and naming consistency

# Check if the subtitle files exist for all locales
echo "Checking subtitle files existence..."
fd -e vtt -p "assets/video/subtitle-video-testimonials.*" 

# Verify consistent naming pattern across locale files
echo "Checking naming pattern in locale files..."
rg -U --multiline '"video-subtitle":\s*"([^"]+)"' shared/locales/

Length of output: 1075

shared/locales/de/website-home.json (1)

23-23: Verify the existence of the subtitle file

The path references a VTT subtitle file. Let's verify its existence and proper formatting.

✅ Verification successful

Subtitle file exists and is properly formatted

The VTT file exists at the correct location (website/public/assets/video/), has proper WEBVTT formatting, and the path in the JSON file correctly references it relative to the public assets directory. The implementation is consistent with other language variants (en_US, fr_FR, it_IT).

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the subtitle file exists and validate its format

# Check if the file exists
fd -t f "subtitle-video-testimonials.de_DE.vtt" public/assets/video

# If found, verify basic VTT format (should start with "WEBVTT")
fd -t f "subtitle-video-testimonials.de_DE.vtt" public/assets/video -x head -n 1 {} \; | grep "WEBVTT"

Length of output: 385


Script:

#!/bin/bash
# Let's first check if the assets directory exists and its location
fd -t d "assets"

# Then search for any VTT files in the repository
fd -t f -e vtt

# Also search for references to VTT files in the codebase
rg "\.vtt" -g '!*.vtt'

Length of output: 1373


Script:

#!/bin/bash
# Let's verify the content of the German VTT file
head -n 5 website/public/assets/video/subtitle-video-testimonials.de_DE.vtt

# Check if the file path in the JSON matches the actual file location
rg -A 1 '"video-subtitle"' shared/locales/de/website-home.json

Length of output: 308

shared/locales/it/website-home.json (1)

23-23: Verify the subtitle file existence and format.

The path follows the correct naming convention. Let's verify the implementation.

✅ Verification successful

✓ Subtitle file exists and follows the correct structure

The verification confirms:

  • The subtitle file subtitle-video-testimonials.it_IT.vtt exists at the correct location: website/public/assets/video/
  • The implementation is consistent with other locales (de_DE, en_US, es_ES, fr_FR also present)
  • The path in the locale file correctly points to the public assets directory
  • The MuxVideoComponent correctly consumes the subtitle path via translations prop
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence and format of the subtitle file

# Check if the subtitle file exists
fd "subtitle-video-testimonials.it_IT.vtt" assets/video

# Validate WebVTT format if file exists
fd "subtitle-video-testimonials.it_IT.vtt" assets/video -x cat {} | head -n 1 | grep -q "^WEBVTT" && echo "Valid WebVTT file" || echo "Invalid or missing WebVTT file"

# Check for consistency across all locales
fd "subtitle-video-testimonials.*\.vtt" assets/video

Length of output: 581


Script:

#!/bin/bash
# Let's first check if the assets directory exists and its location
fd -t d "assets"

# Check for any .vtt files in the repository
fd -e vtt

# Let's also check the MuxVideoComponent to understand the expected structure
rg -A 5 "MuxVideoComponent" 

Length of output: 3123

shared/locales/fr/website-home.json (1)

23-23: Verify the subtitle file existence and format.

The path looks correct, following proper naming conventions with language-region code (fr_FR). However, let's verify:

  1. The existence of the subtitle file
  2. The consistency of paths across other locale files
  3. The validity of the VTT format
✅ Verification successful

✓ Subtitle file path and structure verified

The French subtitle file exists at the correct location website/public/assets/video/subtitle-video-testimonials.fr_FR.vtt, along with other language variants. The path in the locale file /assets/video/subtitle-video-testimonials.fr_FR.vtt is correct as it's relative to the public directory, following the same consistent pattern across all locales (en_US, de_DE, fr_FR, it_IT, es_ES).

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify subtitle file existence, consistency, and format

# Check if the French subtitle file exists
fd "subtitle-video-testimonials.fr_FR.vtt" public/assets/video

# Check naming consistency across all locale files
rg -U '"video-subtitle":\s*"([^"]+)"' shared/locales

# Validate VTT format if file exists
fd "subtitle-video-testimonials.fr_FR.vtt" public/assets/video -x cat {} | grep -E "^WEBVTT|^[0-9]{2}:[0-9]{2}:[0-9]{2}"

Length of output: 894


Script:

#!/bin/bash
# Let's try searching for the subtitle files in the entire repository
# and check the assets directory structure

# Find any .vtt files
fd ".+\.vtt$"

# Check for potential asset directories
fd -t d "assets|public"

# Look for any build/asset configuration files
fd -e json "package.json|next.config.js|vite.config.js|webpack.config.js"

# Search for references to subtitle files or video assets in code
rg -g "!*.json" "subtitle-video-testimonials|assets/video"

Length of output: 1247

@ssandino
Copy link
Member

@mathildedd @mkue we got the answer from the Mux support team who looked at this PR:

Great to hear! So I see you're using the Mux Video element, the handling of captions would be under the vid element as you have. However, when I look and inspect that video element on your landing page, I'm only seeing the English subtitle in there:

Also, the Mux Video should attach all subtitles to the video element if you add the subtitles to your Mux Asset. You could then programmatically set the captions language with something like this:

const tracks = video.textTracks;

        // Function to activate Spanish subtitles
        function setSpanishSubtitle() {
                // Check if the track's language is Spanish (srclang="es")
                if (track.language === 'es') {
                    track.mode = 'showing'; // Display the track
                } else {
                    track.mode = 'disabled'; // Hide other tracks
                }
            }
        }

@ssandino ssandino changed the title issue 934: [Web]: Mux video showing language specific subtitles Website: Hero video optimization (subtitles, flickering) Nov 29, 2024
@ssandino ssandino added the website Issues concerning Website label Nov 29, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Outside diff range and nitpick comments (1)
website/src/app/[lang]/[region]/(website)/(home)/(components)/mux-video.tsx (1)

106-113: Move subtitle styles to CSS module

Inline styles make maintenance harder and mix presentation with logic. Consider moving these styles to a CSS module.

Create a new file mux-video.module.css:

.subtitle {
  background-color: rgba(0, 0, 0, 0.8);
  color: white;
  font-family: Arial, sans-serif;
  font-size: 24px;
}

Then update the component:

-<style>{`
-  video::cue {
-    background-color: rgba(0, 0, 0, 0.8);
-    color: white;
-    font-family: Arial, sans-serif;
-    font-size: 24px;
-    opacity: ${showCaptions ? 1 : 0};
-  }
-`}</style>
+<style>{`
+  video::cue {
+    opacity: ${showCaptions ? 1 : 0};
+  }
+`}</style>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a439fec and ca1085c.

📒 Files selected for processing (1)
  • website/src/app/[lang]/[region]/(website)/(home)/(components)/mux-video.tsx (4 hunks)

Comment on lines 45 to 54
const video = videoElementRef.current;
if (playing && video) {
// Hide poster when video is ready
video.addEventListener('canplay', () => {
if (posterRef.current) {
posterRef.current.style.opacity = '0';
posterRef.current.style.transition = 'opacity 0.5s ease';
}
});
video.play();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add cleanup for canplay event listener

The canplay event listener is not cleaned up when the component unmounts, which could lead to memory leaks.

 useEffect(() => {
   const video = videoElementRef.current;
   if (playing && video) {
-    video.addEventListener('canplay', () => {
+    const handleCanPlay = () => {
       if (posterRef.current) {
         posterRef.current.style.opacity = '0';
         posterRef.current.style.transition = 'opacity 0.5s ease';
       }
-    });
+    };
+    video.addEventListener('canplay', handleCanPlay);
     video.play();
+    return () => video.removeEventListener('canplay', handleCanPlay);
   } else {
     videoElementRef.current?.pause();
   }
 }, [playing]);

Committable suggestion skipped: line range outside the PR's diff.

label="English"
default
/>
<track kind="captions" src={translations.subtitles} srcLang={lang} label="English" default />
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix hardcoded language label in track element

The track element uses a hardcoded "English" label while the component accepts dynamic language props. This could lead to confusion for users of other languages.

-<track kind="captions" src={translations.subtitles} srcLang={lang} label="English" default />
+<track kind="captions" src={translations.subtitles} srcLang={lang} label={lang.toUpperCase()} default />
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<track kind="captions" src={translations.subtitles} srcLang={lang} label="English" default />
<track kind="captions" src={translations.subtitles} srcLang={lang} label={lang.toUpperCase()} default />

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
website/src/app/[lang]/[region]/(website)/(home)/(components)/mux-video.tsx (1)

120-127: Consider extracting subtitle styles to configuration

The subtitle styles could be moved to a configuration file for better maintainability.

+// subtitleConfig.ts
+export const subtitleStyles = {
+  backgroundColor: 'rgba(0, 0, 0, 0.8)',
+  color: 'white',
+  fontFamily: 'Arial, sans-serif',
+  fontSize: '24px',
+};

-          video::cue {
-            background-color: rgba(0, 0, 0, 0.8);
-            color: white;
-            font-family: Arial, sans-serif;
-            font-size: 24px;
-            opacity: ${showCaptions ? 1 : 0};
-          }
+          video::cue {
+            background-color: ${subtitleStyles.backgroundColor};
+            color: ${subtitleStyles.color};
+            font-family: ${subtitleStyles.fontFamily};
+            font-size: ${subtitleStyles.fontSize};
+            opacity: ${showCaptions ? 1 : 0};
+          }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between bf69270 and 6b54fa8.

📒 Files selected for processing (1)
  • website/src/app/[lang]/[region]/(website)/(home)/(components)/mux-video.tsx (4 hunks)
🔇 Additional comments (3)
website/src/app/[lang]/[region]/(website)/(home)/(components)/mux-video.tsx (3)

13-19: LGTM: Clean type definition and component signature

The type definition and component signature are well-structured and properly typed.


20-33: LGTM: Proper error handling implementation

The error handling implementation follows the previous review suggestion with proper state management and cleanup.


57-68: LGTM: Proper event listener cleanup

The canplay event handler implementation follows the previous review suggestion with proper cleanup.

@mdumond
Copy link
Contributor Author

mdumond commented Dec 3, 2024

About subtitles not working on chrome, see muxinc/elements#941 and muxinc/elements#519

Copy link
Contributor

@mkue mkue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6b54fa8 and 4898fcd.

📒 Files selected for processing (1)
  • website/src/app/[lang]/[region]/(website)/(home)/(components)/mux-video.tsx (3 hunks)
🔇 Additional comments (2)
website/src/app/[lang]/[region]/(website)/(home)/(components)/mux-video.tsx (2)

14-20: LGTM: Type definition and component signature

The type definition and component signature changes are well-structured for handling localized subtitles.


21-34: LGTM: Error handling implementation

The error handling implementation follows the previous review suggestion with proper cleanup.

Comment on lines +119 to +128
<track kind="captions" src={translations.subtitles} srcLang={lang} label={lang.toUpperCase()} default />
<style>{`
video::cue {
background-color: rgba(0, 0, 0, 0.8);
color: white;
font-family: Arial, sans-serif;
font-size: 24px;
opacity: ${showCaptions ? 1 : 0};
`}</style>
video::cue {
background-color: rgba(0, 0, 0, 0.8);
color: white;
font-family: Arial, sans-serif;
font-size: 24px;
opacity: ${showCaptions ? 1 : 0};
}
`}</style>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Missing subtitle files need to be added

The translation files reference subtitle VTT files at /assets/video/, but these files are not present in the repository:

  • /assets/video/subtitle-video-testimonials.de_DE.vtt
  • /assets/video/subtitle-video-testimonials.en_US.vtt
  • /assets/video/subtitle-video-testimonials.fr_FR.vtt
  • /assets/video/subtitle-video-testimonials.it_IT.vtt
🔗 Analysis chain

Verify subtitle file availability

The subtitle implementation looks correct, but we need to verify the subtitle files exist at the paths specified in translations.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if subtitle files exist in public assets
fd -e vtt . public/assets/video

# Check subtitle paths in translation files
rg "video-subtitle.*\.vtt" shared/locales

Length of output: 624


Script:

#!/bin/bash
# Check if subtitle files exist in public directory
fd -e vtt subtitle-video-testimonials public

Length of output: 140

Comment on lines +58 to +69
const video = videoElementRef.current;
if (playing && video) {
// Hide poster when video is ready
const handleCanPlay = () => {
if (posterRef.current) {
posterRef.current.style.opacity = '0';
posterRef.current.style.transition = 'opacity 0.5s ease';
}
};
video.addEventListener('canplay', handleCanPlay);
video.play();
return () => video.removeEventListener('canplay', handleCanPlay);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix potential race condition in video playback

There's a potential race condition between video.play() and the canplay event listener. The video might start playing before the poster fade-out is complete.

Apply this fix:

 if (playing && video) {
   const handleCanPlay = () => {
     if (posterRef.current) {
       posterRef.current.style.opacity = '0';
       posterRef.current.style.transition = 'opacity 0.5s ease';
     }
+    video.play();
   };
   video.addEventListener('canplay', handleCanPlay);
-  video.play();
   return () => video.removeEventListener('canplay', handleCanPlay);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const video = videoElementRef.current;
if (playing && video) {
// Hide poster when video is ready
const handleCanPlay = () => {
if (posterRef.current) {
posterRef.current.style.opacity = '0';
posterRef.current.style.transition = 'opacity 0.5s ease';
}
};
video.addEventListener('canplay', handleCanPlay);
video.play();
return () => video.removeEventListener('canplay', handleCanPlay);
const video = videoElementRef.current;
if (playing && video) {
// Hide poster when video is ready
const handleCanPlay = () => {
if (posterRef.current) {
posterRef.current.style.opacity = '0';
posterRef.current.style.transition = 'opacity 0.5s ease';
}
video.play();
};
video.addEventListener('canplay', handleCanPlay);
return () => video.removeEventListener('canplay', handleCanPlay);

@mkue mkue merged commit 892b5fc into main Dec 3, 2024
15 of 16 checks passed
@mkue mkue deleted the 934-video-subtitle-translation branch December 3, 2024 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
website Issues concerning Website
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Web]: Mux video flickers when played on Safari
4 participants